<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="../common/header.jsp"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<c:set var="ctx" value="${pageContext.request.contextPath }"></c:set>
<script src="js/jquery-3.5.1.js" type="text/javascript"></script>
<!-- 增加页面开始 -->
<div class="x_content">
	<form class="form-horizontal form-label-left" id="query"
		action="${ctx }/addStudent" method="post" novalidate>
		<span class="section">学生注册页面</span>

		<div class="item form-group">
			<label class="control-label col-md-3 col-sm-3 col-xs-12">专业
				<span class="required">*</span>
			</label>
			<div class="col-md-6 col-sm-6 col-xs-12">
				<select name="major" id="major" required="required"
					class="form-control col-md-7 col-xs-12">
					<option value="">---请选择---</option>
					<c:forEach var="maj" items="${majors }">
						<option value="${maj.major}">${maj.major}</option>
					</c:forEach>
				</select>
			</div>
		</div>

		<div class="item form-group">
			<label class="control-label col-md-3 col-sm-3 col-xs-12">班级
				<span class="required">*</span>
			</label>
			<div class="col-md-6 col-sm-6 col-xs-12">
				<select name="classID" id="classname" required="required"
						class="form-control col-md-7 col-xs-12">
					<option value="">---请选择---</option>
					<c:forEach var="cla" items="${cList }">
						<option value="${cla.classId}"
								<c:if test="${cla.classId == studentInfo.classId}">
									selected
								</c:if>
						>${cla.className}</option>
					</c:forEach>
				</select>
			</div>
		</div>


		<div class="item form-group">
			<label class="control-label col-md-3 col-sm-3 col-xs-12">姓名
				<span class="required">*</span>
			</label>
			<div class="col-md-6 col-sm-6 col-xs-12">
				<input type="text" id="name" name="name"
					data-validate-linked="email" required="required"
					class="form-control col-md-7 col-xs-12">
			</div>
		</div>
		<div class="item form-group">
			<label class="control-label col-md-3 col-sm-3 col-xs-12"
				>来自院校 <span class="required">*</span>
			</label>
			<div class="col-md-6 col-sm-6 col-xs-12">
				<input id="fromschool" type="tel" name="fromschool"
					data-validate-length-range="5,20" required="required"
					class="optional form-control col-md-7 col-xs-12">
			</div>
		</div>
		<div class="item form-group">
			<label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">学历(大专/本科)<span
				class="required">*</span>
			</label>
			<div class="col-md-6 col-sm-6 col-xs-12">
				<select name="education" id="education" required="required"
					class="form-control col-md-7 col-xs-12">
					<option value="">---请选择---</option>
					<option value="专科">专科</option>
					<option value="本科">本科</option>
				</select>
			</div>
		</div>
		<div class="item form-group">
			<label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">登录账号(姓名拼音)<span
				class="required">*</span>
			</label>
			<div class="col-md-6 col-sm-6 col-xs-12">
				<input id="username" class="form-control col-md-7 col-xs-12"
					data-validate-length-range="6" data-validate-words="2"
					name="username" required="required" type="text">
			</div>
		</div>
		<div class="item form-group">
			<label class="control-label col-md-3 col-sm-3 col-xs-12">登录密码
				<span class="required">*</span>
			</label>
			<div class="col-md-6 col-sm-6 col-xs-12">
				<input type="password" id="userpwd" name="userpwd"
					required="required" class="form-control col-md-7 col-xs-12">
			</div>
		</div>

		<div class="form-group">
			<div class="col-md-6 col-md-offset-3">
				<input type="submit" value="提交" class="btn btn-primary" />
				<button type="reset" class="btn btn-success">重置</button>
				<a href="${ctx}/chaservlet.do" id="send" type="button"
					class="btn btn-success">取消</a>
			</div>
		</div>
	</form>
</div>
<!-- 增加页面结束 -->
<%@ include file="../common/footer.jsp"%>
<script src="${ctx }/statics/localjs/StuAdd.js"></script>
<script>
	$(function (){
		if($("#major").val()==""||$("#major").val()==null){
			//在页面加载的时候获取到省列表
			var param={
				majorId:null
			};
			$.getJSON("studentAjax.do?operation=major",param, function(data){
				$("#major").html("");
				var options="<option value='' >---请选择---</option>";
				for(var i=0;i<data.length;i++){
					options+="<option value='"+data[i].major+"' >"+data[i].major+"</option>";
				}
				$("#major").html(options);
			});
		}

		$("#major").change(function(){
			var major=$("#major").val();
			if (null!=major&&major!="") {
				$.ajax({
					type:"POST",//提交方式，默认GET
					url:"${ctx }/studentAjax.do?operation=class",//提交的服务器地址
					data:"major="+major,
					dataType:"json",
					success:function(data){
						$("#classname").html("");
						var options="<option value='' >---请选择---</option>";
						for(var i=0;i<data.length;i++){
							options+="<option value='"+data[i].classId+"' >"+data[i].className+"</option>";
						}
						$("#classname").html(options);
					},
					error:function(){
						alert('加载二级菜单失败！');
						location.href="401.jsp"
					}
				});
			}else{
				$("#classname").html("");
				var options="<option value='' >---请选择---</option>";
				$("#classname").html(options);
			}
		});
	});
</script>